package com.ruitu.mall_98.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.beanu.arad.base.my_base.Config;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.beanu.arad.base.my_base.base_list.SuperViewHolder;
import com.ruitu.mall_98.R;
import com.ruitu.mall_98_1.product.activity.ProductListByModelActivity;
import com.ruitu.router_module.bean.app.BannerNew;
import com.ruitu.router_module.utils.GlideUtil;

/**
 * Created by Administrator on 2018/3/29.
 */
public class HorizontalDataAdapter extends ListBaseAdapter<BannerNew> {

    public HorizontalDataAdapter(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.app_item_horizontal_product;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int pos) {
        ImageView icon = holder.getView(R.id.icon);

        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) icon.getLayoutParams();
        params.height = params.width * 400 / 300;//比例300*400
        icon.setLayoutParams(params);

        BannerNew jingxuan = mDataList.get(pos);
        if (null != jingxuan) {
            GlideUtil.loadImg(Config.BASE_URL + jingxuan.getImgApp(), icon);
        }

        setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                try {
                    Intent intent = new Intent(mContext, ProductListByModelActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("type", mDataList.get(position).getId());
                    bundle.putString("model_name", mDataList.get(position).getName());
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
